package com.baizhi.controller;

import com.baizhi.client.FeignProductClient;
import com.baizhi.entity.Product;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class IndexController {
    @Autowired
    private FeignProductClient fpc;
    @GetMapping("selectAll")
    @HystrixCommand(fallbackMethod = "testFall")//指定出现异常的时候要调用的方法
    public String selectAll(){
        String s = fpc.selectOne(1);
        return "我是首页模块的测试方法！！！"+s;
    }
    @GetMapping("/selectOne/{id}")
    public String selectOne(@PathVariable("id") int id){
        Product product = fpc.selectOne2(id);
        return "我是首页模块的selectone。。。"+product;
    }
    //熔断器打开后要执行的方法。
    public String testFall(){
        return "熔断器打开，目标方法不能使用。。。。";
    }
}
